home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / System7 tools / Frontier / Frontier SDK 2.1 / Toolkits / Applet Toolkit / appletmenuops.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-11  |  4.2 KB  |  224 lines  |  [TEXT/KAHL]

  1.  
  2. /*© Copyright 1988-1992 UserLand Software, Inc.  All Rights Reserved.*/
  3.  
  4.  
  5. #include "appletstrings.h"
  6. #include "appletmenuops.h"
  7.  
  8.  
  9. boolean pushmenuitem (MenuHandle hmenu, bigstring bs, boolean flenabled) {
  10.     
  11.     short item;
  12.     bigstring bstemp;
  13.     
  14.     item = CountMItems (hmenu) + 1; /*new item will be after current end*/
  15.     
  16.     if (equalstrings (bs, "\p(-")) /*take disabled seperator as is*/
  17.         AppendMenu (hmenu, bs);
  18.     
  19.     else { /*to allow meta-characters in bs, append blank item, then set item text*/
  20.         
  21.         setstringwithchar (chspace, bstemp);
  22.         
  23.         AppendMenu (hmenu, bstemp);
  24.         
  25.         copystring (bs, bstemp); /*work with a copy*/
  26.         
  27.         if (equalstrings (bstemp, "\p-")) /*this is one meta-character that it won't ignore*/
  28.             copystring ("\p\0-", bstemp);
  29.         
  30.         if (!isemptystring (bs))
  31.             SetItem (hmenu, item, bstemp);
  32.         }
  33.     
  34.     if (!flenabled)
  35.         DisableItem (hmenu, item);
  36.  
  37.     return (true);
  38.     } /*pushmenuitem*/
  39.     
  40.     
  41. void deletemenuitem (MenuHandle hmenu, short ixmenu) {
  42.     
  43.     DelMenuItem (hmenu, ixmenu);
  44.     } /*deletemenuitem*/
  45.     
  46.  
  47. boolean getmenuitem (MenuHandle hmenu, short ixmenu, bigstring bs) {
  48.     
  49.     if (ixmenu <= 0)
  50.         return (false);
  51.         
  52.     GetItem (hmenu, ixmenu, bs);
  53.         
  54.     return (true);
  55.     } /*getmenuitem*/
  56.  
  57.  
  58. boolean setmenuitem (MenuHandle hmenu, short ixmenu, bigstring bs) {
  59.     
  60.     SetItem (hmenu, ixmenu, bs);
  61.     } /*setmenuitem*/
  62.     
  63.     
  64. void checkmenuitem (MenuHandle hmenu, short ixmenu, boolean fl) {
  65.         
  66.     CheckItem (hmenu, ixmenu, fl);
  67.     } /*checkmenuitem*/
  68.     
  69.     
  70. boolean visitonemenu (short idmenu, tymenuvisitcallback visitproc) {
  71.     
  72.     register MenuHandle hmenu;
  73.     register short i;
  74.     register short lastitem;
  75.     
  76.     hmenu = GetMHandle (idmenu);
  77.     
  78.     if (!hmenu)
  79.         return (false);
  80.     
  81.     lastitem = countmenuitems (hmenu);
  82.     
  83.     for (i = 1; i <= lastitem; i++) {
  84.         
  85.         if (!(*visitproc) (hmenu, i))
  86.             return (false);
  87.         } /*for*/
  88.  
  89.     return (true);
  90.     } /*visitonemenu*/
  91.  
  92.  
  93. void stylemenuitem (MenuHandle hmenu, short ixmenu, short style) {
  94.     
  95.     SetItemStyle (hmenu, ixmenu, style);
  96.     } /*stylemenuitem*/
  97.     
  98.     
  99. void installmenu (short idmenu, MenuHandle *hmenu) {
  100.  
  101.     *hmenu = GetMenu (idmenu); 
  102.     
  103.     if (*hmenu != nil) /*defensive driving*/
  104.         InsertMenu (*hmenu, 0);
  105.     } /*installmenu*/
  106.     
  107.     
  108. void installhierarchicmenu (short idmenu, MenuHandle *hmenu) {
  109.  
  110.     *hmenu = GetMenu (idmenu); 
  111.     
  112.     if (*hmenu != nil) 
  113.         InsertMenu (*hmenu, -1);
  114.     } /*installhierarchicmenu*/
  115.     
  116.     
  117. void setmenuitemenable (hmenu, item, fl) MenuHandle hmenu; short item; boolean fl; {
  118.     
  119.     /*
  120.     enable or disable a menu or a menu item.  if fl is true we enable the item,
  121.     if false we disable it.
  122.     
  123.     if item == 0 we enable or disable the entire menu.
  124.     
  125.     dmb 8/1/90:  check for dummy items (negative item numbers)
  126.     */
  127.     
  128.     if (item < 0) /*this item has been dummied out -- do nothing*/
  129.         return;
  130.     
  131.     if (fl)
  132.         EnableItem (hmenu, item);
  133.     else
  134.         DisableItem (hmenu, item);
  135.         
  136.     if (item == 0)
  137.         DrawMenuBar ();
  138.     } /*setmenuitemenable*/
  139.     
  140.     
  141. void disablemenuitem (hmenu, item) MenuHandle hmenu; short item; {
  142.     
  143.     setmenuitemenable (hmenu, item, false);
  144.     } /*disablemenuitem*/
  145.     
  146.  
  147. void enablemenuitem (hmenu, item) MenuHandle hmenu; short item; {
  148.     
  149.     setmenuitemenable (hmenu, item, true);
  150.     } /*enablemenuitem*/
  151.  
  152.  
  153. short countmenuitems (MenuHandle hmenu) {
  154.     
  155.     return (CountMItems (hmenu));
  156.     } /*countmenuitems*/
  157.     
  158.     
  159. void uncheckallmenuitems (MenuHandle hmenu) {
  160.     
  161.     register short i;
  162.     register short ct;
  163.     
  164.     ct = countmenuitems (hmenu);
  165.     
  166.     for (i = 1; i <= ct; i++)
  167.         CheckItem (hmenu, i, false);
  168.     } /*uncheckallmenuitems*/
  169.     
  170.     
  171. void disableallmenuitems (MenuHandle hmenu) {
  172.     
  173.     register short i;
  174.     register short ct;
  175.     
  176.     ct = countmenuitems (hmenu);
  177.     
  178.     for (i = 1; i <= ct; i++)
  179.         setmenuitemenable (hmenu, i, false);
  180.     } /*disableallmenuitems*/
  181.     
  182.     
  183. void enableallmenuitems (MenuHandle hmenu) {
  184.     
  185.     register short i;
  186.     register short ct;
  187.     
  188.     ct = countmenuitems (hmenu);
  189.     
  190.     for (i = 1; i <= ct; i++)
  191.         setmenuitemenable (hmenu, i, true);
  192.     } /*enableallmenuitems*/
  193.     
  194.     
  195. void disableemptymenuitems (MenuHandle hmenu) {
  196.     
  197.     short i, j;
  198.     short ctmenuitems;
  199.     
  200.     ctmenuitems = countmenuitems (hmenu);
  201.     
  202.     for (i = 1; i <= ctmenuitems; i++) {
  203.         
  204.         boolean flnotempty = false;
  205.         bigstring bs;
  206.         
  207.         getmenuitem (hmenu, i, bs);
  208.         
  209.         for (j = 1; j <= stringlength (bs); j++) {
  210.             
  211.             if (bs [j] != ' ') {
  212.                 
  213.                 flnotempty = true;
  214.                 
  215.                 break;
  216.                 }
  217.             } /*for*/
  218.     
  219.         setmenuitemenable (hmenu, i, flnotempty);
  220.         } /*for*/
  221.     } /*disableemptymenuitems*/
  222.     
  223.     
  224.